<?php


namespace app\shop\controller\admin;


use app\enterprise\model\Message;
use app\shop\controller\BaseAdminController;
use app\shop\model\config\ArticleModel;
use app\shop\model\user\UserModel;
use think\App;
use think\Request;

class ArticleController extends BaseAdminController
{

    public function __construct(App $app)
    {
        $this->namespace = __NAMESPACE__;
        $this->model = new ArticleModel();
        $this->search = $this->setSearch($app->request);
        parent::__construct($app);
    }

    function setSearch(Request $request)
    {
        return [
            'like' => ['title'],
        ];
    }

    public function save(array $data = [])
    {
        $data = $this->request->param();
        if (!isset($data['id'])) {
            $uidArr = UserModel::where('user_id', '>', 1)->column('user_id');
            foreach ($uidArr as $uid) {
                // 通知客户
                $message = Message::createMessageData(1, $uid, 'notice', $data['title']);
                Message::sendMessage($message);
            }
        }
        parent::save($data);
        return $this->success();
    }
}